//
//  HDLY_UserInfo.m
//  HDJinShaSiteMuseum
//
//  Created by liuyi on 2017/6/29.
//  Copyright © 2017年 HDNiuKuiming. All rights reserved.
//

#import "HDLY_UserInfo.h"

@implementation HDLY_UserInfo
+ (id)sharedUserInfo
{
    static id userInfo;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        userInfo = [[self alloc] init];
    });
    
    return userInfo;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        
    }
    return self;
}

- (void)recordUseLoginAction:(NSDictionary *)loginDic
{
    if (loginDic != nil && [loginDic isKindOfClass:[NSDictionary class]]) {
        //保存登录信息
        [self writePlist:loginDic];
    }
    else if (loginDic == nil) {
        //清空登录信息
        NSDictionary *userDic = @{@"lastLoginUserID":@"",
                                  @"lastLoginUserPwd":@"",
                                  @"lastLoginDeviceNum":@""};
        [self writePlist:userDic];
    }
}

- (void)writePlist:(NSDictionary *)dic // 用户登录信息
{
    NSString *filename = [kCachePath stringByAppendingPathComponent:@"userLogin.plist"];
    NSFileManager *fm = [NSFileManager defaultManager];
    if (![fm fileExistsAtPath:filename])
        [fm createFileAtPath:filename contents:nil attributes:nil];
    //创建一个dic，写到plist文件里
    [dic writeToFile:filename atomically:YES];
}

- (NSDictionary *)readFromPlist {
    //读文件
    NSString *filename = [kCachePath stringByAppendingPathComponent:@"userLogin.plist"];
    NSDictionary* dic2 = [NSDictionary dictionaryWithContentsOfFile:filename];
    return dic2;
}



@end












